package models

//物品表
type Object1 struct {
	Object1 string `gorm:"column:object1"`
	Ratio   string `gorm:"column:ratio"`
}

func GetAllObject1(Object1Param map[string]interface{}) (error, []Object1, int64) {
	var object1Data []Object1
	page := Object1Param["page"].(int)
	pageSize := Object1Param["limit"].(int)
	searchText := Object1Param["searchText"].(string)
	var total int64
	err := db.Table("object1").Where("object1 like ?", "%"+searchText+"%").Order("ratio ASC").Count(&total).Find(&object1Data).Offset((page - 1) * pageSize).Limit(pageSize).Error
	return err, object1Data, total
}
func AddObject1(object1data Object1) (error, Object1) {
	err := db.Table("object1").Select("object1", "ratio").Create(&object1data).Error
	return err, object1data
}

func UpdateObject1(object1 string, object1data Object1) (error, Object1) {
	err := db.Table("object1").Where("object1 = ?", object1data.Object1).Updates(&object1data).Error
	return err, object1data
}

func DeleteObject1(object1 string) (error, Object1) {
	var object1data Object1
	object1data.Object1 = object1
	err := db.Table("object1").Where("object1 = ?", object1).Find(&object1data).Delete(Object1{}).Error
	return err, object1data
}
